package day_2022_7_to_8.day48;

/**
 * @author haomin
 * @date 2022/08/21 19:38
 **/
public class Day36_6_Num80_RemoveDuplicates {
    class Solution {
        // 单指针
        public int removeDuplicates(int[] nums) {
            int i = 0;
            for(int num : nums){
                if(i < 2 || nums[i-2] != num)
                    nums[i++] = num;
            }
            return i;
        }
    }
    class Solution2 {
        // 快慢指针
        public int removeDuplicates(int[] nums) {
            int i = 0, count = 0;
            for(int j = 1; j < nums.length; ++j){
                if(nums[i] != nums[j]){
                    nums[++i] = nums[j];
                    count = 0;
                } else if(nums[i] == nums[j]){
                    count ++;
                    if(count < 2){
                        nums[++i] = nums[j];
                    }else {
                        continue;
                    }
                }
            }
            return i+1;
        }
    }
}